package com.bdqn.service.impl;

import com.bdqn.entity.Category;
import com.bdqn.mapper.CategoryMapper;
import com.bdqn.param.response.Page;
import com.bdqn.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 服务实现类
 * </p>
 *
 * @author hunter
 * @since 2022-06-11
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Page<Category> pageInfo(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Category> categories = categoryMapper.selectList(null);
        PageInfo pageInfo = new PageInfo(categories);
        //封装分页对象
        return new Page(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public Category checkName(String name) {
        return categoryMapper.checkName(name);
    }

    @Override
    public List<Category> selectByTypeId(Integer id) {
        return categoryMapper.selectByTypeId(id);
    }
}
